import axios, {CancelToken} from "./config"
// axios : 基于http客户端的promise，面向浏览器和nodejs axios 依赖原生的 ES6 Promise 实现而被支持.
//登入
export const login =(username,password)=>axios({
url:"users/login",
method:"post",
data:{
    username,
    password
}
})

// import axios from "axios"

// axios.defaults.baseURL = "/api"


//获取登入日志
/**
 * 
 * @param {Object} _this  一个组件实列 
 */
export  const getLoginLog =(_this)=>
axios.get("/getloginlog",{
    canceToken:new CanceToken(function(c){
        //c就是一个方法，可以终止请求
        _this.cancel=c  //相当于给组件实例，添加一个cancel属性
    })
})

//获取用户菜单
export const getMenuList= ()=>axios.get("/permission/getMenuList")

// //获取全部学生资料
// export const getInformatio = () => axios.get("/students/getstulist")


// 删除学员
export const getDetail = (sId) => axios.get(`/students/delstu?sId=${sId}`)

//获取验证码
export const getCaptcha= ()=>axios.get("/users/getCaptcha")

//刷新验证码
export const refreshCaptcha= ()=>axios.get("/users/refreshCaptcha")
//校验验证码
export const verifyCaptcha= (captcha)=>axios.get(`/users/verifyCaptcha?captcha=${captcha}`)

// 获取学员信息
export const getInformatio=(params={})=>axios({
  url:"/students/getstulist",
  params
})
  // 增加学员信息
  export const addStuDetail = (stuDetail) => axios({
    url: '/students/addstu',
    method: 'post',
    data: stuDetail
  })

  //编辑学员信息
  export const updateStuDetail = (update={}) => axios({
    url: '/students/updatestu',
    method: 'post',
    data: update
  })

// 查询学员
export const searchstu = (key) => axios.get(`/students/searchstu?key=${key}`)

//获取班级
export const getClasses= ()=>axios.get("/students/getclasses")